const { registerSrv } = require("hope");

const aesKeySymbol = Symbol["pwdCrypt#aesKey"];

const encrypt = require("./lib/encrypt");

const decrypt = require("./lib/decrypt");

registerSrv(
	"hopePwdCrypt",
	{
		aesKey: "hope.pwd"
	},
	function () {
		this.__init = function (opts) {
			this[aesKeySymbol] = opts.aesKey || "hope.pwd";
		};

		/**
		 * 加密明文密码
		 *      refer : Dropbox的密码加密方式
		 * @param {String} password 明文密码
		 * @return {String} 密文
		 */
		this.encrypt = encrypt(aesKeySymbol);

		/**
		 * 比较两个密码
		 *
		 * @param {String} password 明文密码
		 * @param {String} cryptedPassword 加密后的密码
		 *
		 * @return {Boolean} 是否为同一明文密码
		 */
		this.compare = decrypt(aesKeySymbol);
	}
);
